<?php
namespace app\common\model;
use app\admin\model\Admin;
use think\Model;
use think\model\concern\SoftDelete;

class CustomerPrice extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;

    protected $type = [
        'datetime'     => 'timestamp:Y-m-d',
    ];

    /**
     * 关联用户
     * @return \think\model\relation\BelongsTo
     */
    public function customer()
    {
        return $this->belongsTo(Customer::class,'customer_id','id')->bind(['customer_name'=>'name']);
    }

    /**
     * 关联用户
     * @return \think\model\relation\BelongsTo
     */
    public function hetong()
    {
        return $this->belongsTo(CustomerHetong::class,'hetong_id','id')->bind(['hetong_name'=>'name']);
    }

    /**
     * 关联用户
     * @return \think\model\relation\BelongsTo
     */
    public function type()
    {
        return $this->belongsTo(DictData::class,'type_id','id')->bind(['type_name'=>'name']);
    }

    /**
     * 关联用户
     * @return \think\model\relation\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(Admin::class,'user_id','id')->bind(['user_name'=>'name']);
    }
    
    /**
     * 权限转数组 保存
     * @param $value
     * @return array|string
     */
    public function setFilesAttr($value)
    {
        if(!$value){
            $list = array();
        }else{
            $list = implode(',',array_filter($value));
        }
        return $list;
    }

    /**
     * 权限转数组 读取
     * @param $value
     * @return array|false|string[]
     */
    public function getFilesAttr($value)
    {
        if(!$value){
            $list = array();
        }else{
            $list = explode(',', $value);
        }
        return $list;
    }


}